﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using BLL;
using Model;
using Common;

namespace Controllers
{
    public class BlogController : Controller
    {
        
        public ActionResult Index(string catename,string tagname,int page=1)
        {
            string extsql = " and blog_type=1 ";
            string url ="/Blog/Page/";
            if (!string.IsNullOrEmpty(catename))
            {
                url = "/Blog/Cate/"+ catename+"/";
                CategoryBLL catebll = new CategoryBLL();
                extsql += " and blog_cate like '%【"+ catebll.GetCateID(catename) + "】%'";
            }
            if (!string.IsNullOrEmpty(tagname))
            {
                url = "/Blog/Tag/"+ tagname+"/";
                TagBLL tagbll = new TagBLL();
                extsql += " and blog_tags like '%【" + tagbll.GetTagID(tagname) + "】%'";
            }

            if (page <= 0)
            {
                page = 1;
            }
            if(page==1)
            {
                ViewBag.prepage = url+page;
            }
            else
            {
                ViewBag.prepage = url+(page - 1);
            }
            ViewBag.nexpage = url+(page + 1);
            BlogBLL bll = new BlogBLL();
            ViewBag.mess = bll.GetPage(extsql, page, 10);
            return View();
        }

        public ActionResult Model(string id)
        {
            BlogBLL bll = new BlogBLL();
            Blog blog= bll.GetModel(id);
            if(blog==null)
            {
              return Redirect("/");
            }
            ViewBag.model = blog;
            return View();
        }
       

    }
}